home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig13_03.jar / Ch13 / Fig13_03 / fig13_03.cpp
C/C++ Source or Header  |  1997-11-02  |  546b  |  36 lines

  1. // Fig. 13.3: fig13_03.cpp
  2. // Demonstrating stack unwinding.
  3. #include <iostream>
  4. #include <stdexcept>
  5.  
  6. using namespace std;
  7.  
  8. void function3() throw ( runtime_error )
  9. {
  10.    throw runtime_error( "runtime_error in function3" );
  11. }
  12.  
  13. void function2() throw ( runtime_error )
  14. {
  15.    function3();
  16. }
  17.  
  18. void function1() throw ( runtime_error )
  19. {
  20.    function2();
  21. }
  22.  
  23. int main()
  24. {
  25.    try {
  26.       function1();
  27.    }
  28.    catch ( runtime_error e )
  29.    {
  30.       cout << "Exception occurred: " << e.what() << endl;
  31.    }
  32.  
  33.    return 0;
  34. }
  35.  
  36.